import 'dart:async';

import 'package:flutter/material.dart';

// ignore: must_be_immutable
class ImageView extends StatefulWidget {
  final String imageOne;
  final String imageTwo;
  bool isChange;
  Timer timer;
  int _countdownTime = 0;
  ImageView({
    Key key,
    this.imageOne,
    this.imageTwo,
    this.isChange = false,
  }) : super(key: key);

  @override
  _ImageViewState createState() => _ImageViewState();
}

class _ImageViewState extends State<ImageView> {
  @override
  @override
  void initState() {
    super.initState();
    //监听滚动事件，打印滚动位置
    Timer.periodic(Duration(seconds: 4), (timer) {
        setState(() {
          widget.isChange = !widget.isChange;
        });
    });
  }

  @override
  void dispose() {
    // _controller.dispose();
    super.dispose();
  }
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      // onTap: () {
      //   setState(() {
      //     widget.isChange = !widget.isChange;
      //   });
      // },
      child: Container(
          height: 525,
          width: 498,
          child: Stack(
            alignment: Alignment.bottomCenter,
            children: [
              AnimatedOpacity(
                duration: Duration(seconds: 1),
                opacity: widget.isChange?0:1,
                child: Image.network(
                  widget.imageOne,
                  fit: BoxFit.fill,
                ),
              ),
              AnimatedOpacity(
                duration: Duration(seconds: 1),
                opacity: widget.isChange?1:0,
                child: Image.network(
                  widget.imageTwo,
                  fit: BoxFit.fill,
                ),
              ),
              Container(
                width: 50,
                padding: EdgeInsets.only(bottom: 10),
                child: Row(
                  children: [
                    ClipOval(
                      child: AnimatedContainer(
                        duration: Duration(seconds: 1),
                        color: widget.isChange ? Colors.white : Colors.black,
                        width: widget.isChange ? 12 : 10,
                        height: widget.isChange ? 12 : 10,
                      ),
                    ),
                    SizedBox(width: 20,),
                    ClipOval(
                      child: AnimatedContainer(
                        duration: Duration(seconds: 1),
                        color: widget.isChange ? Colors.black : Colors.white,
                        width: widget.isChange ? 10 : 12,
                        height: widget.isChange ? 10 : 12,
                      ),
                    ),
                  ],
                ),
              ),

            ],
          )),
    );
  }
}
